<?php
class HolidaysController extends Zend_Controller_Action
{
	public function init()
	{
		IndexController::initAdmin($this);
	}
	
	public function indexAction()
	{
		$objHolidays = new QHolidays($this->AppUI->country);
		$arrResult	= $objHolidays->getAll();
		
		$this->view->arrResult	= $arrResult;
	}
	
	public function addAction()
	{
		$objHolidays = new QHolidays($this->AppUI->country);
		if($this->_request->isPost())
		{
			$intId			= $this->_request->getParam('intId', null);
			$strDate		= $this->_request->getParam('strDate', null);
			$strWeekday		= $this->_request->getParam('strWeekday', null);
			$strDescription	= $this->_request->getParam('strDescription', null);
			
			$arrInfo	= $objHolidays->get_by_date($strDate);
			
			if($arrInfo && $arrInfo['id'] != $intId)
			{
				echo '<script>parent.show_error("'.$strDate. '", "exists")</script>';
				exit;
			}
			
			if(!$intId)
			{
				$arrParams	= array
				(
					'date'			=> $strDate,
					'weekday'	=> $strWeekday,
					'description'	=> $strDescription,
				);
				$objHolidays->insert($arrParams);
				echo '<script>parent.submit_done()</script>';
			}
			else
			{
				$arrParams		= array
				(
					'id'			=> $intId,
					'date'			=> $strDate,
					'weekday'		=> $strWeekday,
					'description'	=> $strDescription,
				);
				$objHolidays->update($arrParams, $intId);
				echo '<script>parent.submit_done()</script>';
			}
			exit;
		}
		
		$intId	= $this->_request->getParam('intId');
		if($intId)
		{
			$arrResult	= $objHolidays->get_by_id($intId);
			$this->view->arrResult	= $arrResult;
		}
	}
	
	public function deleteAction()
	{
		$intId			= $this->_request->getParam('intId', null);
		$objHolidays = new QHolidays($this->AppUI->country);
		$objHolidays->delete($intId);
		echo '<script> window.location.href ="'. HOST . '/holidays' . '"</script>';
		exit;
	}
}
?>
